package com.iheima.reggie_take.common;

/**
 * Created with IntelliJ IDEA.
 * ClassName: BaseContext
 * Package: com.iheima.reggie_take.config
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-01-17
 * Time: 14:27
 */

/**
 * 基于ThreadLocal 封装的工具类 用户保存和获取当前登录用户id
 * 线程为作用域 每个线程单独保存自己的
 */

public class BaseContext {

    //指定泛型 存储用户的id
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    // 设置值
    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }

    //获取值
    public static Long getCurrentId(){
        return threadLocal.get();
    }
}
